package com.example.exam.shiro;

import com.example.exam.user.model.UserBean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 自定义认证主体
 */
public class ShiroPrincipal implements Serializable {

	private static final long serialVersionUID = 1428196040744555722L;
	// 用户id
	private Integer userId;
	// 登陆名称
	private String loginName;
	// 用户名称
	private String userName;
	// 用户区域id
	private String areaId;

	private String token;

	private UserBean user;

	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	// 用户权限列表
	private List<String> authorities = new ArrayList<String>();
	// 用户角色列表
	private List<String> roles = new ArrayList<String>();
	// 是否已授权。如果已授权，则不需要再从数据库中获取权限信息，减少数据库访问
	// 这里会导致修改权限时，需要重新登录方可有效
	private boolean isAuthorized = false;

	public ShiroPrincipal() {
		super();
	}

	public ShiroPrincipal(UserBean loginUser) {
		super();
		UserBean user = new UserBean();
		user.setId(loginUser.getId());
		user.setShow_name(loginUser.getShow_name());
		user.setLogin_name(loginUser.getLogin_name());
		user.setToken(loginUser.getToken());
		this.userId = loginUser.getId();
		this.loginName = loginUser.getLogin_name();
		this.userName = loginUser.getShow_name();
		this.token = loginUser.getToken();
		this.user = user;
	}

	public List<String> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(List<String> authorities) {
		this.authorities = authorities;
	}

	public List<String> getRoles() {
		return roles;
	}

	public void setRoles(List<String> roles) {
		this.roles = roles;
	}

	public boolean isAuthorized() {
		return isAuthorized;
	}

	public void setAuthorized(boolean isAuthorized) {
		this.isAuthorized = isAuthorized;
	}

	/**
	 * <shiro:principal/>标签显示中文名称
	 */
	@Override
	public String toString() {
		return this.userName;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public UserBean getUser() {
		return user;
	}

	public void setUser(UserBean user) {
		this.user = user;
	}

}
